<?php
/**
 * Created by PhpStorm.
 * User: 王松
 * Time: 2017/9/13 17:30
 */

namespace App\Transformers\Reservation;

use App\Models\Reservation\Pool;
use Carbon\Carbon;
use League\Fractal\TransformerAbstract;

class PoolListTransformer extends TransformerAbstract
{
    protected $carbon;

    public function __construct()
    {
        $this->carbon = new Carbon();
    }

    public function transform(Pool $pool)
    {
        return [
            'id'               => $pool->id,
            'patient_id'       => $pool->patient_id,
            'name'             => $pool->patient->name,
            'age'              => $pool->patient->age,
            'birthday'         => $pool->patient->birthday,
            'sex'              => $pool->patient->sex,
            'phone'            => $pool->patient->phone,
            'reservation_date' => $pool->reservation->time,
            'reservation_time' => [
                'reservation_start' => $this->carbon->hour($pool->reservation->start)->format('H:00'),
                'reservation_end'   => $this->carbon->hour($pool->reservation->end)->format('H:00')
            ],
            'is_reception'     => $pool->is_reception ? true : false,
            'created_at'       => $pool->created_at->toDateTimeString(),
            'updated_at'       => $pool->updated_at->toDateTimeString(),
        ];
    }
}